#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
#include<queue>
#include<stack>
#include <functional>
#include <memory>
using namespace std;

class Solution {
public:
    vector<int> findOrder(int numCourses, vector<vector<int>>& prerequisites) {
        unordered_map<int, vector<int>> map;
        vector<int> in(numCourses, 0);

        for (auto& ch : prerequisites)
        {
            in[ch[0]]++;
            map[ch[1]].push_back(ch[0]);
        }
        queue<int> qt;
        for (int i = 0; i < numCourses; i++)
        {
            if (in[i] == 0) qt.push(i);
        }

        vector<int> ret;
        while (qt.size())
        {
            int num = qt.front();
            ret.push_back(num);
            qt.pop();
            for (auto ch : map[num])
            {
                in[ch]--;
                if (in[ch] == 0) qt.push(ch);
            }
        }

        for (int i = 0; i < numCourses; i++)
        {
            if (in[i] != 0) return {};
        }

        return ret;
    }
};

int main()
{
	return 0;
}